package cn.stazxr.component;

import java.awt.*;
import java.awt.event.WindowAdapter;

/**
 * Package: cn.stazxr.component
 * Dialogtest
 *
 * @Author: stazxr
 * @Create: 2023/12/9
 * @Version: v1.0
 **/
public class Dialogtest {
    public static void main(String[] args) {
        Frame frame = new Frame("Hello World");
        frame.setBounds(500, 500, 500, 300);
        frame.setAlwaysOnTop(true);

        Dialog dialog = new Dialog(frame, "Dialog exit Y/N", true);
        dialog.setResizable(false);
        dialog.add(new Label("Are you sure you want to exit the program?"), BorderLayout.NORTH);   //对话框默认采用的是边界布局
        dialog.add(new Button("cancel"), BorderLayout.WEST);
        dialog.add(new Button("exit"), BorderLayout.EAST);
        dialog.setSize(300, 100);
        dialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent e) {
                dialog.setVisible(false);
            }
        });

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent e) {
                dialog.setVisible(true);
            }
        });

        frame.setVisible(true);
    }
}
